<?php
/**
 * Created by PhpStorm.
 * User: qttx
 * Date: 2019/5/30
 * Time: 13:58
 */
namespace app\admin\model;

class PhoneServiceModel extends BaseModel
{
    protected $table = "xst_phone_service";
    protected $rule = [
        'id' => '',
    ];
    protected $msg = [
        'id' => '',
    ];
	//手机充值查询
    public function index($condition = 1)
    {
      if(input('get.sub')){
            $phone = input('phone');
            if(!empty($phone)){
                $condition = "ps.phone = $phone";
            }
        }
        return $this->alias('ps')
			->join('xst_user u','u.id=ps.uid')
            ->where($condition)
			->order('ps.createtime desc')
			->field('ps.id,nickname,money,ps.phone,ps.createtime,ps.status')
			->paginate(10,false,['query'=>request()->param()]);
    }
    public function getOneId($id)
    {
        return $this->where('id',$id)->find();
    }
    //充值信息删除
    public function del()
    {
        $id = request()->post('id');
        return $this->where('id',$id)->delete();
    }

    //充值信息多删
    public function dell()
    {
        $id = request()->post('id');
        return $this->where('id','in',$id)->delete();
    }
    //充值状态修改
	public function IsStatus($id,$status){
        $res=$this->where('id',$id)->update(['status'=>$status]);
        if($res){
            if ($status==1)
                $status = ['code'=>1,'msg'=>'开启成功'];
            else
                $status = ['code'=>1,'msg'=>'已禁用'];
        }else{
            if ($status==1)
                $status = ['code'=>0,'msg'=>'开启失败'];
            else
                $status = ['code'=>0,'msg'=>'禁用失败'];
        }
        return $status;
    }
}